#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：HiflyVideoAPI_Test 
@File    ：TestCaseV1VoicesList.py
@Author  ：beibei
@Date    ：7/16/25 3:25 PM 
'''
import unittest

from business.voices.vo import BusinessRe
from common.assertCommon import AssertCommon
from common.yamlLoader import YamlRead
from common.caseOutput import info, class_case_decoration
from utils.utils_base import save_json_response, extract_voice_by_type_v1


@class_case_decoration
class TestCaseV1VoicesList(unittest.TestCase):
    """
    测试用例：测试v1——高保真声音列表接口
    """
    ac = AssertCommon()
    env_config = YamlRead().env_config1()
    host = env_config['host']
    br = BusinessRe()
    authorization = env_config['Authorization']

    def testCase01_v1_voices_list(self):
        """获取声音列表"""
        info('【step】获取当前用户声音数据')
        url = self.host + f'/api/v1/hifly/voice/list'
        res = self.br.get(url, self.authorization)
        info('【step】断言 code == 0')
        self.ac.code_assert(0, res.json()["code"])
        save_json_response(res.json(), "data/response/voice/v1/voice_list_v1.json")

    def testCase02_V1_voice_edit(self):
        """编辑type=20的声音信息"""
        info('【step】获取type=20的声音ID')
        voice_dict = extract_voice_by_type_v1(path="data/response/voice/v1/voice_list_v1.json", types=(20,))
        voice_list = voice_dict.get(20)
        assert voice_list, "voice_list_v1.json中没有type=20的声音"
        voice_id = voice_list[0]

        info('【step】编辑声音')
        url = self.host + f'/api/v1/hifly/voice/edit'
        body = {
            "voice_id": voice_id,
            "title": "自动化V1编辑type20声音_测试",
            "rate": "1.2",
            "pitch": "1.5",
            "volume": "1.2"
        }
        res = self.br.post(url, self.authorization, body)
        info('【step】断言 code == 0')
        self.ac.code_assert(0, res.json()["code"])
        save_json_response(res.json(), "data/response/voice/v1/voice_edit_v1.json")
